<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-29 23:31:37
 * @lastTime 2020-05-01 23:16:14
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Design\Other\Repository;

class Post
{

    private $id;

    private $status;

    private $title;

    private $text;


    public static function draft(PostId $id, string $title, string $text) : Post
    {
        return new self(
            $id,
            PostStatus::fromString(PostStatus::STATE_DRAFT),
            $title,
            $text
        );

    }//end draft()


    public static function fromState(array $state) : Post
    {
        return new self(
            PostId::fromInt($state['id']),
            PostStatus::fromString($state['status']),
            $state['title'],
            $state['text']
        );

    }//end fromState()


    private function __construct(PostId $id, PostStatus $status, string $title, string $text)
    {
        $this->id     = $id;
        $this->status = $status;
        $this->title  = $title;
        $this->text   = $text;

    }//end __construct()


    public function getId() : PostId
    {
        return $this->id;

    }//end getId()


    public function getStatus() : PostStatus
    {
        return $this->status;

    }//end getStatus()


    public function getText() : string
    {
        return $this->text;

    }//end getText()


    public function getTitle() : string
    {
        return $this->title;

    }//end getTitle()


}//end class
